package com.epfly.api.promo.activity;


import com.epfly.base.hv.UpdateGroup;
import com.epfly.base.vo.BaseResp;
import com.epfly.base.vo.PageResp;
import com.epfly.base.vo.RowsResp;
import com.epfly.iface.promo.activity.ActivityService;
import com.epfly.iface.promo.activity.ActivityURL;
import com.epfly.iface.promo.activity.vo.*;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Validated
@RestController
public class ActivityBootController {

    @Resource
    private ActivityService activityService;

    @PostMapping(value = "/activity/performActivityAdd")
    public ResponseEntity<ActivityAddAndUpdateResp> performActivityAdd(@RequestBody @Validated ActivityAddAndUpdateRequest activityAddRequest) {
        ActivityAddAndUpdateResp resp = activityService.performActivityAdd(activityAddRequest);
        return ResponseEntity.ok(resp);
    }

    @GetMapping(value = "/activity/performActivityList")
    public ResponseEntity<PageResp<ActivityListVo>> performActivityList(@Validated ActivityListRequest activityListRequest) {
        PageResp<ActivityListVo> resp = activityService.performActivityList(activityListRequest);
        return ResponseEntity.ok(resp);
    }

    @PostMapping(value = "/activity/alterActivityIsActive")
    public ResponseEntity<BaseResp> alterActivityIsActive(@RequestBody AlterActivityIsActiveRequest request) {
        BaseResp resp = activityService.alterActivityIsActive(request);
        return ResponseEntity.ok(resp);
    }

    @PostMapping(value = "/activity/performActivityTerminated")
    public ResponseEntity<BaseResp> performActivityTerminated(@RequestBody @Validated ActivityTerminatedRequest request) {
        BaseResp resp = activityService.performActivityTerminated(request);
        return ResponseEntity.ok(resp);
    }

    @PostMapping(value = "/activity/performActivityUpdate")
    public ResponseEntity<BaseResp> performActivityUpdate(@RequestBody @Validated(value = {UpdateGroup.class}) ActivityAddAndUpdateRequest activityAddRequest) {
        activityService.performActivityUpdate(activityAddRequest);
        return ResponseEntity.ok(BaseResp.OK);
    }

    @GetMapping(value = "/activity/performActivityDetail")
    public ResponseEntity<ActivityDetailResp> performActivityDetail(@NotNull(message = "活动ID不能为空") Long activityId) {
        ActivityDetailResp resp = activityService.performActivityDetail(activityId);
        return ResponseEntity.ok(resp);
    }

    @GetMapping(value = "/activity/storeCount")
    public ResponseEntity<RowsResp<StoreCountVo>> storeCount(@Validated StoreCountRequest request) {
        RowsResp<StoreCountVo> resp = activityService.storeCount(request);
        return ResponseEntity.ok(resp);
    }

}
